using System.Collections.Generic;
using DefaultNamespace;
using UnityEngine;
/// <summary>
///状态同步：简化实现（Unity伪代码)
///场景：服务器同步玩家位置，客户端只做插值。
/// </summary>
public class StateSyncManager : MonoBehaviour
{
    public Dictionary<int, Player> players = new();
    
    void Update()
    {
        foreach (var player in players.Values)
        {
            // 客户端平滑插值显示位置
            player.transform.position = Vector3.Lerp(player.transform.position, player.targetPosition, Time.deltaTime * 10f);
        }
    }
    
    // 从服务器接收到状态更新
    void OnReceiveState(int playerId, Vector3 serverPos)
    {
        if (players.TryGetValue(playerId, out var player))
        {
            player.targetPosition = serverPos;
        }
    }
}